package com.zyms.controller.api;

import com.zyms.cache.redis.RedisCache;
import com.zyms.controller.baseController.WebBaseController;
import com.zyms.module.result.ResultObj;
import com.zyms.module.sms.SMSChangePassWord;
import com.zyms.module.user.User;
import com.zyms.service.ProducerService;
import com.zyms.service.UserService;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Baggio on 2018-1-24.
 */
@RequestMapping("/api/index")
@Controller
public class IndexController  extends WebBaseController {

    @Autowired
    UserService userService;
    @Autowired
    ProducerService producerService;
    @Autowired
    RedisCache redisCache;
    @RequestMapping(value="/index",method = RequestMethod.POST)
    @ResponseBody
    public ResultObj apiIndex(HttpServletRequest request, HttpServletResponse response, Long activityId) {
        logger.info("=============================index==============================================>>>>>>"+activityId);
        ResultObj resultObj=new ResultObj();
   /*     try {*/
           /* redisCache.put("1111","123");
            producerService.sendDataToQueue("queueSMSKey","123456");
            String ss=(String)redisCache.get("1111");
            logger.info("ss=====>>>"+ss);*/
           //  producerService.sendQueue("exchangeSMS","queueSMSKey","12346");
            MessageProperties messageProperties=new MessageProperties();
        Map<String,String> map=new HashMap<String, String>();
        map.put("phone","13618267496");
        map.put("code","123456");
        /*    try {
        byte[] body = null;
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject(map);
            body=os.toByteArray();

            oos.close();
            os.close();


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 Message message=new Message(body,messageProperties);*/
        SMSChangePassWord smsRegedit=new SMSChangePassWord();
        smsRegedit.setPhone("13618267496");
        smsRegedit.setCode("654321");
            producerService.sendDataToQueue("queueSMSKey",smsRegedit);
            User user=new User();
            userService.login(user);
            resultObj.setData("aaaaaaaaaaaaaaaaaaaaaaaaaa");
      /*  } catch (MyRunTimeExcption myRunTimeExcption) {
            resultObj.setCode(myRunTimeExcption.getErroCode());
            resultObj.setMsg(myRunTimeExcption.getMessage());
            logger.info(myRunTimeExcption.getMessage());
            myRunTimeExcption.printStackTrace();
        }catch (Exception e) {
            resultObj.setCode(ResultObj.CODE_FAIL);
            resultObj.setMsg(e.getMessage());
            logger.info("Exception============>>>>"+e.getMessage());
         //   e.printStackTrace();
        }*/
        return resultObj;
    }
}
